// pages/togroupinto/togroupinto.js
const app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headsrc: app.data.imgurl +"headimg.png",
    getmyhuiyuaninfo: app.data.url + 'sheyingjia/Xhuiyuan1/getmyhuiyuaninfo',
    tianxiegerenkuaidi: app.data.url + 'sheyingjia/Xhuiyuan1/tianxiegerenkuaidi',
    shuju:{},
    system:{}
  },
  //填写数据
  tianxie:function(e){
    console.log(e);
    var type = e.currentTarget.dataset.type;
    var value = e.detail.value;
    var shuju = this.data.shuju;
    shuju[type] = value;
    console.log(shuju);
    this.setData({shuju:shuju});
  },
  //点击下一步
  xiayibu:function(){
    var shuju = this.data.shuju;
    var that = this;
    if (!shuju.kuaidi){
      wx.showToast({
        title: '请填写快递公司',
        icon:'none'
      })
      return;
    }
    if (!shuju.kuaidi_danhao) {
      wx.showToast({
        title: '请填写快递单号',
        icon: 'none'
      })
      return;
    }
    var user = wx.getStorageSync('user');
    wx.showLoading({
      title: '加载中',
    })
    ea.request(that.data.tianxiegerenkuaidi,{shuju:shuju,token:user.token},function(res){
      var data = res.data;
      console.log(data);
      // return;
      if(data.code==200){
        wx.navigateTo({
          url: '/pages/mailexamine/mailexamine',
        })
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var user = wx.getStorageSync('user');
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    ea.request(that.data.getmyhuiyuaninfo,{token:user.token},function(res){
      wx.hideLoading();
      var data =res.data;
      console.log(data.data);
      if(data.code==200){
        var shuju = data.data.data;
        if (shuju.jindu !='下载申请表'){
          wx.navigateTo({
            url: '/pages/mailexamine/mailexamine',
          })
        }
        that.setData({ shuju: data.data.data, system: data.data.system});
      }else{
        wx.showToast({
          title: data.msg,
          icon:'none'
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    // wx.reLaunch({
    //   url: '/pages/member/member',
    // })
    wx.switchTab({
      url: '/pages/index/index',
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})